<?php


namespace app\admin\controller;

use app\model\member\MemberOpenAccount as MemberOpenAccountModel;

/**
 * 会员进件记录 控制器
 */
class Memberopenaccount extends BaseAdmin
{

    public function lists()
    {
        if(request()->isAjax()){
            $page = input('page', 1);
            $page_size = input('page_size', PAGE_LIST_ROWS);
            $search_text = input('search_text', '');

            $alias = 'a';

            $join = [
                [ 'member_open_account oa', 'oa.member_id = a.member_id', 'left' ]
            ];

            $condition = [
                ['a.account_type','=',0]
            ];

            $condition[] = ['a.realname|a.mobile', 'like', "%". $search_text ."%"];

            $order = 'a.create_time desc';
            $field = 'a.*';

            $member_label_model = new MemberOpenAccountModel();
            $list = $member_label_model->getMemberOpenAccountPageList($condition, $page, $page_size, $order, $field,$alias,$join);
            return $list;
        }else{
            return $this->fetch('memberopenaccount/lists');
        }
    }

    public function enterpriselist()
    {
        if(request()->isAjax()){
            $page = input('page', 1);
            $page_size = input('page_size', PAGE_LIST_ROWS);
            $search_text = input('search_text', '');

            $alias = 'a';

            $join = [
                [ 'member_open_account oa', 'oa.member_id = a.member_id', 'left' ]
            ];

            $condition = [
                ['a.account_type','=',1]
            ];

            $condition[] = ['a.enterprise_name', 'like', "%". $search_text ."%"];

            $order = 'a.create_time desc';
            $field = 'a.*';

            $member_label_model = new MemberOpenAccountModel();
            $list = $member_label_model->getMemberOpenAccountPageList($condition, $page, $page_size, $order, $field,$alias,$join);
            return $list;
        }else{
            return $this->fetch('memberopenaccount/enterpriselist');
        }
    }


    public function detail()
    {
        $account_id = input('account_id',0);

        $member_label_model = new MemberOpenAccountModel();

        $info = $member_label_model->getMemberOpenAccountInfo([['account_id','=',$account_id]]);

        $this->assign('info',$info['data']);

        return $this->fetch('memberopenaccount/detail');
    }

    public function enterprisedetail()
    {
        $account_id = input('account_id',0);

        $member_label_model = new MemberOpenAccountModel();

        $info = $member_label_model->getMemberOpenAccountInfo([['account_id','=',$account_id]]);

        $this->assign('info',$info['data']);

        return $this->fetch('memberopenaccount/enterprisedetail');
    }


    //通过
    public function pass()
    {
        if (request()->isAjax()) {
            $model = new MemberOpenAccountModel();

            $account_id = input('account_id', '');

            $result = $model->pass($account_id,1);
            return $result;
        }
    }

    //拒绝
    public function fail()
    {
        if (request()->isAjax()) {
            $model = new MemberOpenAccountModel();

            $account_id = input('account_id', '');

            $result = $model->pass($account_id,2);
            return $result;
        }
    }
}